//
//  HSYBaseQRCodeViewController+RAC.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/6/19.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYBaseQRCodeViewController+RAC.h"
#import "NSObject+RACDescription.h"
#import "RACDelegateProxy.h"

@implementation HSYBaseQRCodeViewController (RAC)

static void RACUseDelegateProxy(HSYBaseQRCodeViewController *self) {
    
    if (self.delegate == (id)self.rac_delegateProxy) return;
    self.rac_delegateProxy.rac_proxiedDelegate = self.delegate;
    self.delegate = (id)self.rac_delegateProxy;
}

- (RACDelegateProxy *)rac_delegateProxy {
    
    RACDelegateProxy *proxy = objc_getAssociatedObject(self, _cmd);
    if (proxy == nil) {
        proxy = [[RACDelegateProxy alloc] initWithProtocol:@protocol(HSYBaseQRCodeViewControllerDelegate)];
        objc_setAssociatedObject(self, _cmd, proxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
    return proxy;
}

- (RACSignal *)rac_didOutput {
    
    RACSignal *signal = [[[self.rac_delegateProxy signalForSelector:@selector(didOutputMetadataObject:)] reduceEach:^(NSString *result) {
        return result;
    }] setNameWithFormat:@"%@ - rac_didOutput", self.rac_description];
    
    RACUseDelegateProxy(self);
    
    return signal;
}

@end
